package com.activenetwork.smlite.testcase.events.createEvents.basics;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.schema.model.event.EventBasicType;
import com.activenetwork.smlite.page.event.EventDetailView.EventBasicSubview;
import com.activenetwork.smlite.snippet.EventsSnippet;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.verification.gson.FailureAssertion;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Basics006 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(Basics006.class);
	private EventBasicType.Location urumqi;
	private EventBasicType.Location utopia;
	/**
	 * "Urumqi" location is in account 1, private = true
	 * "Utopia" location is in accout 2, private = false
	 * 
	 * Check these two accounts for location, if data missing, create it
	 */
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup() {
		urumqi = new EventBasicType.Location();
		urumqi.setLocationName("Urumqi");
		urumqi.setPrivate(true);
		
		utopia = new EventBasicType.Location();
		utopia.setLocationName("Utopia");
		utopia.setPrivate(false);
	}
	
	@Test
	public void Verify_isPrivate_feature_of_new_location(){
		loginBusiness.login("autotest4@activenetwork.com", "st@rc!te");
		
		// Verify Urumqi existed under autotest4 account
		// if not, add it
		EventBasicSubview eventBasicSubview = EventsSnippet.gotoAddEventPage();
		try{
			eventBasicSubview = eventBasicSubview.selectEventLocationAJAX(urumqi);
		}catch(RuntimeException e){
			EventBasicType utopiaEvent = new EventBasicType();
			utopiaEvent.setLocation(urumqi);
			eventBasicSubview.setEventLocation(utopiaEvent);
			eventBasicSubview.saveLocation();
		}finally{
			eventBasicSubview.logout();
		}
		
		
		// Verify Utopia existed under autotest5 account
		// if not, add it
		loginBusiness.login("autotest5@activenetwork.com", "st@rc!te");
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		try{
			eventBasicSubview = eventBasicSubview.selectEventLocationAJAX(utopia);
		}catch(RuntimeException e){
			EventBasicType utopiaEvent = new EventBasicType();
			utopiaEvent.setLocation(utopia);
			eventBasicSubview.setEventLocation(utopiaEvent);
			eventBasicSubview.saveLocation();
		}finally{
			loginBusiness.logout();
		}
		
		// Verify in the smlite@starcite.com, Urumqi is displaying, Utopia is displaying 
		// smlite@starcite.com with autotestX@activenetwork.com belonging to same account
		loginBusiness.login("smlite@starcite.com", "st@rc!te");
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		try{
			eventBasicSubview = eventBasicSubview.selectEventLocationAJAX(urumqi);
			logger.info("Verify private address should be seen in its own account succeeded");
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Basics006.class.getName(), 
					"Verify private address should be seen in its own account", 
					"Private address can not be seen in its own account"));
		}finally{
			eventBasicSubview.events();
		}
		

		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		try{
			eventBasicSubview = eventBasicSubview.selectEventLocationAJAX(utopia);
			logger.info("Verify public address should be seen in any account succeeded");
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Basics006.class.getName(), 
					"Verify public address should be seen in other account", 
					"Public address can not be seen in other account"));
		}finally{
			loginBusiness.logout();
		}
		
		// Verify in the helen.yuan@starcite.com, Urumqi is NOT displaying, Utopia is displaying
		// helen.yuan@starcite.com is belonging to another account
		loginBusiness.login("helen.yuan@starcite.com", "111111");
		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		try{
			eventBasicSubview = eventBasicSubview.selectEventLocationAJAX(urumqi);
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Basics006.class.getName(), 
					"Verify private address should NOT be seen in other account", 
					"Private address can be seen in other account"));
		}catch(RuntimeException e){
			logger.info("Verify private address should NOT be seen in other account succeeded");
		}finally{
			eventBasicSubview.events();
		}

		eventBasicSubview = EventsSnippet.gotoAddEventPage();
		try{
			eventBasicSubview = eventBasicSubview.selectEventLocationAJAX(utopia);
			logger.info("Verify public address should be seen in any account succeeded");
		}catch(RuntimeException e){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Basics006.class.getName(), 
					"Verify public address should be seen in its own account", 
					"Public address can not be seen in its own account"));
		}finally{
			loginBusiness.logout();
			FailureAssertion.pop(Basics006.class);
		}
	}
	
	
	
}
